<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "bas_member".
 *
 * @property int $id ID
 * @property string $numbering 会员编号
 * @property string $mini_openid 小程序openid
 * @property string $openid 微信openid
 * @property string $unionid 平台唯一id
 * @property string $avatar 头像
 * @property string $phone 手机号
 * @property string $password 密码
 * @property string $name 昵称
 * @property int $br_id 分馆id
 * @property int $audit 审核是否通过0.未提交1.审核中2.通过3.拒绝
 * @property int $isrule 协议是否同意，0，不同意，1 同意
 * @property string $isrule_time 同意时间
 * @property int $reg_ip 注册IP
 * @property int $login_ip 最后登录IP
 * @property int $islog 是否登录;1,登录;2,退出
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 * @property string $id_number 身份证
 * @property string $user_name 姓名
 */
class BasMember extends \yii\db\ActiveRecord
{
    public $user_status;
    public $branch_count;

    /**
     * 自动更新时间
     */
    public function behaviors()
    {
        return [
            [
                'class' => \yii\behaviors\TimestampBehavior::className(),
                'value' => function () {
                    return date('Y-m-d H:i:s');
                },
            ],
        ];
    }
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'bas_member';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['br_id', 'audit', 'isrule', 'reg_ip', 'login_ip', 'islog'], 'integer'],
            [['isrule_time', 'created_at', 'updated_at', 'deleted_at'], 'safe'],
            [['numbering'], 'string', 'max' => 32],
            [['mini_openid', 'openid'], 'string', 'max' => 64],
            [['unionid', 'name', 'id_number', 'user_name'], 'string', 'max' => 255],
            [['avatar'], 'string', 'max' => 500],
            [['phone'], 'string', 'max' => 15],
            [['password'], 'string', 'max' => 200],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'numbering' => '编号',
            'mini_openid' => '小程序Openid',
            'openid' => '微信Openid',
            'unionid' => '微信Unionid',
            'avatar' => '头像',
            'phone' => '电话',
            'password' => '密码',
            'name' => '昵称',
            'br_id' => 'Br ID',
            'audit' => 'Audit',
            'isrule' => 'Isrule',
            'isrule_time' => 'Isrule Time',
            'reg_ip' => 'Reg Ip',
            'login_ip' => '最后登录IP',
            'islog' => 'Islog',
            'created_at' => '创建时间',
            'updated_at' => 'Updated At',
            'deleted_at' => 'Deleted At',
            'id_number' => '身份证号',
            'user_name' => '姓名',
            'user_status' => '账号状态',
            'branch_count' => '分馆数量',
        ];
    }

    /**
     * 场景
     */
    const SCENARIOS_USER_INSERT = 'branch_insert';

    public function scenarios()
    {
        $scenarios = [
            self::SCENARIOS_USER_INSERT => [
                'phone',
                'user_name',
                'id_number',
            ],
        ];
        return array_merge(parent::scenarios(), $scenarios);
    }
}
